from uuid import uuid1

from info_collect import db
from info_collect.models import Teacher
from info_collect.models import obj_to_dict


def create_teacher(body):
    """
    Create teacher
    
    :param body: Created teacher object
    :type body: dict | bytes

    :rtype: None
    """
    id = unicode(uuid1())
    u = Teacher(id)
    u.firstname = body.get('firstname')
    u.lastname = body.get('lastname')
    u.email = body.get('email')
    u.phone = body.get('phone')
    u.wechat = body.get('wechat')
    db.session.add(u)
    db.session.commit()
    return obj_to_dict(u)


def delete_teacher(teacherId):
    """
    Delete teacher
    Delete a teacher.
    :param teacherId: ID of the teacher
    :type teacherId: int

    :rtype: None
    """
    u = Teacher.query.get(teacherId)
    db.session.delete(u)
    db.session.commit()
    return obj_to_dict(u)


def get_teacher(teacherId):
    """
    Get teacher by teacher name
    
    :param teacherId: ID of the teacher
    :type teacherId: int

    :rtype: Teacher
    """
    u = Teacher.query.get(teacherId)
    return obj_to_dict(u)


def list_teacher():
    """
    List teachers
    

    :rtype: List[Teacher]
    """
    ul = Teacher.query.all()
    return [obj_to_dict(u) for u in ul]


def login_teacher(body):
    """
    Logs teacher into the system
    
    :param body: The teacher name for login
    :type body: dict | bytes

    :rtype: str
    """
    return 'do some magic!'


def logout_teacher():
    """
    Logs out current logged in teacher session
    

    :rtype: None
    """
    return 'do some magic!'


def update_teacher(teacherId, body):
    """
    Updated teacher
    Update information of a teacher.
    :param teacherId: ID of the teacher
    :type teacherId: int
    :param body: Updated teacher object
    :type body: dict | bytes

    :rtype: None
    """
    return 'do some magic!'
